package com.xique.community.api.factory;

import com.xique.common.core.domain.R;
import com.xique.community.api.RemoteCommunityUserService;
import com.xique.community.api.model.CommunityUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 用户服务降级处理
 * 
 * @author xique
 */
@Component
public class RemoteCommunityUserFallbackFactory implements FallbackFactory<RemoteCommunityUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteCommunityUserFallbackFactory.class);

    @Override
    public RemoteCommunityUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteCommunityUserService()
        {
            @Override
            public R<CommunityUser> getUserInfo(Long userId) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<List<CommunityUser>> getUserList(List<Long> userIds) {
                return R.fail("获取用户列表失败:" + throwable.getMessage());
            }
        };
    }
}
